package de.piratech.dasding.data.database.couch.adapters;

import java.util.List;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.codehaus.jackson.map.annotate.JsonRootName;

import de.piratech.dasding.data.ActionCategory;
import de.piratech.dasding.data.User;
import de.piratech.dasding.data.database.couch.DataType;
import javax.xml.bind.annotation.XmlRootElement;

@JsonRootName("User")
@JsonIgnoreProperties(ignoreUnknown = true)
@XmlRootElement
public class UserAdapter extends User {

	private String rev;
	private DataType dataType;

	public UserAdapter() {
	}

	public UserAdapter(User user) {
		this.setActionApplications(user.getActionApplications());
		this.setId(user.getId());
		this.setInterestedIn(user.getInterestedIn());
		this.setMail(user.getMail());
		this.setMobile(user.getMobile());
		this.setName(user.getName());
		this.setPassword(user.getPassword());
		this.setPhone(user.getPhone());
		this.setRoles(user.getRoles());
	}

	@JsonProperty("_id")
	public String getId() {
		return super.getId();
	}
    
	@JsonProperty("_rev")
	public String getRevision() {
		return this.rev;
	}

	public void setRevision(String rev) {
		this.rev = rev;
	}

	public DataType getDataType() {
		return dataType;
	}

	public void setDataType(DataType dataType) {
		this.dataType = dataType;
	}

	@Override
	@JsonIgnore
	public boolean isValid() {
		return super.isValid();
	}

	@Override
	@JsonDeserialize(contentAs = ActionCategoryAdapter.class)
	public void setInterests(List<ActionCategory> interests) {
		super.setInterests(interests);
	}
}
